package org.hxzon.workeasy.pages.job;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hxzon.workeasy.model.EasyJob;
import org.hxzon.workeasy.pages.base.MyBasePage;
import org.hxzon.workeasy.service.EasyJobService;

public class EditJob extends MyBasePage {

    @Inject
    private EasyJobService jobSer;
    @Property
    private EasyJob job;
    @InjectPage
    private ListJob listJob;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object init(String id) {
        job = jobSer.findById(id);
        return null;
    }

    @OnEvent(component = "update")
    Object update() {
        jobSer.save(job);
        return listJob.initialize("all");
    }

    @OnEvent(value = EventConstants.PASSIVATE)
    Object onPassivate() {
        return job.getId();
    }
}
